import { defineStore } from "pinia"
import { ref } from "vue"

import router from "@/router/index.js"

import { getMenuListApi } from "@/api/permission"



import allRoutes from "@/router/dynamicRoutes"


import recursionRoutes from "@/utils/recursionRoutes"


import commonRoutes from "../router/commonRoutes"

export default defineStore('menulist', () => {

    let isCollapse = ref(false)


    let menulist = ref([])


    let getMenuList = () => new Promise(async (resolve, reject) => {
        // console.log(123)
        let result = await getMenuListApi()

     

        let userRoutes = recursionRoutes(allRoutes, result.data.menuList)

        commonRoutes.children = userRoutes;

       
        router.addRoute(commonRoutes)

    

        menulist.value = userRoutes;

        resolve()
    })
    return { menulist, getMenuList, isCollapse }
})